package com.bwie.gddproject.search.model;

import com.bwie.gddproject.net.NetUtil;
import com.bwie.gddproject.net.OnNetLitenner;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by 我走路带风 on 2017/12/16.
 */

public class SearchModel implements ISearchModel {
    @Override
    public void getGoods(final OnNetLitenner<GoodsBean> onNetLitenner, String keywords, String page) {
        NetUtil.getResponseService().searchGoods(keywords, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GoodsBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GoodsBean goodsBean) {
                        onNetLitenner.success(goodsBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        onNetLitenner.fail(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
